﻿import QtQuick
import QtQuick.Controls
Rectangle{
    id:bar

    property Window win
    property int topBtnSize: 30
    property double iconSize: topBtnSize * 0.6
    property color normalColor: "#4a4a4a"   // 默认近黑


//    x:win.x
//    y:win.y
//    width:win.width
//    height:75
//    anchors.left: parent.left
//    anchors.top: parent.top
//    anchors.right: parent.right

    color:"transparent"



    Connections{
        target: bar.win
        function onVisibilityChanged(v){
            switch(v){
            case Window.Windowed: btn_max.isMaxed = false
                break
            case Window.Maximized: btn_max.isMaxed = true
                break
            }
        }
    }



    Row{
        anchors.right: parent.right
        anchors.top:parent.top

        anchors.rightMargin: 20
        anchors.topMargin: 20


        spacing: 5

        NoFrameButton{
            id:btn_setting
            width: topBtnSize
            height: topBtnSize

            icon {
                source: "qrc:/images/setting.png"
                width: iconSize
                height: iconSize
                color: btn_setting.isHovered  ? "black" : normalColor
            }


            needHoverTimer: true
            //悬浮效果
            //hoverEnabled: true
            tipText: "设置"
            onClicked: {

            }
        }

        // Separator
        Rectangle{
            width: 2
            height: topBtnSize
            color: Qt.lighter("grey",1.8)
        }
        

        NoFrameButton{
            id:btn_min
            width: topBtnSize
            height: topBtnSize

            icon {
                source: "qrc:/images/zuixiaohua.png"
                width: iconSize
                height: iconSize
                color: btn_min.isHovered  ? "black" : Qt.lighter(normalColor,1.5)
            }


            needHoverTimer: true
            //悬浮效果
            //hoverEnabled: true
            tipText: "最小化"
            onClicked: win.showMinimized()
        }

        NoFrameButton{
            id: btn_max
            width: topBtnSize
            height: topBtnSize

            property bool isMaxed

            icon {

                source:btn_max.isMaxed ?  "qrc:/images/huanyuan.png" : "qrc:/images/zuidahua.png"
                width: iconSize
                height: iconSize
                color: btn_max.isHovered  ? "black" : normalColor
            }


            needHoverTimer: true
            //悬浮效果
            //hoverEnabled: true
            tipText: isMaxed ? "向下还原" : "最大化"

            onClicked: {
                if(isMaxed){
                    win.showNormal()
                    isMaxed = false
                }
                else{
                    win.showMaximized()
                    isMaxed = true
                }
            }



        }

        NoFrameButton{
            id:btn_close
            width: topBtnSize
            height: topBtnSize

            icon {
                source: "qrc:/images/guanbi.png"
                width: iconSize
                height: iconSize
                color: btn_close.isHovered  ? "red" : normalColor
            }

            needHoverTimer: true
            tipText: "关闭"

            onClicked: win.close()
        }

    }
}
